package cn.yuan.quartz.service.impl;

import cn.yuan.quartz.jobs.MainJob;
import cn.yuan.quartz.service.IQuartzService;
import cn.yuan.quartz.utils.QuartzJobInfo;
import cn.yuan.quartz.utils.QuartzUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService{
    @Autowired
    private SchedulerFactoryBean schedulerFactory;
    @Override
    public void addJob(QuartzJobInfo info) {
        QuartzUtils.addJob(schedulerFactory.getScheduler(), info.getJobName(), MainJob.class, JSONObject.toJSONString(info), info.getCronj() );
    }

    @Override
    public void removeJob(String jobName) {
        QuartzUtils.removeJob(schedulerFactory.getScheduler(), jobName);
    }
}
